<template>
  <!-- 关注的 -->

  <div id="attention_list">
    <ul id="attention_list1">
      <mescroll-vue
        ref="mescroll2"
        :down="mescrollDown2"
        :up="mescrollUp2"
        @init="mescrollInit2"
      >
        <li
          v-for="(item, n) in attention_list"
          :key="n"
          class="list"
          :class="{
            'current-conversation-item':
              'C2C' + item.im === currentConversation.conversationID,
          }"
          @click="select(item.im, item)"
        >
          <span class="is_online_true" v-if="item.im"></span>
          <span class="is_online_false" v-else></span>
          <div class="acter_user">
            <img src="@/assets/img/sex1.png" class="im_avatar" alt />
            <span v-if="item.unread > 0">{{ item.unread }}</span>
          </div>
          <div class="acter_text">
            <div>
              <!-- <div class="user_im">{{ item.nickname }}</div>
              <div class="user_time">{{ item.im }}</div> -->
              <div class="user_im">{{ item.im }}</div>
              <div class="user_time">{{ item.nickname }}</div>
            </div>
            <p class="hid_text liuyan">{{ item.username }}</p>
          </div>
        </li>
      </mescroll-vue>
      <div class="noneData" v-if="attention_list.length == 0">
        <img src="@/assets/img/im/noneData.png" alt="" />
        <!-- <i style="font-size: 40px" class="el-icon-chat-line-square"></i> -->
        <span>暂无相关数据~</span>
      </div>
    </ul>
  </div>
</template>

<script>
import MescrollVue from "mescroll.js/mescroll.vue"; //下拉组件
import { mapState } from "vuex";
export default {
  name: "",
  props: {
    search: [String, Number],
  },
  data() {
    return {
      selToID: "",
      mescroll2: null, // mescroll实例对象
      mescrollDown2: {
        mustToTop: true,
      }, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
      mescrollUp2: {
        // 上拉加载的配置.
        callback: this.upCallback2, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
        //以下是一些常用的配置,当然不写也可以的.
        page: {
          num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
          size: 10, //每页数据条数,默认10
        },
        htmlNodata: '<p class="upwarp-nodata">-- END --</p>',
        noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看这就是为什么无更多数据有时候不显示的原因
        toTop: {
          //回到顶部按钮
          src: "./static/mescroll/mescroll-totop.png", //图片路径,默认null,支持网络图
          offset: 1000, //列表滚动1000px才显示回到顶部按钮
        },
        // empty: {
        //   //列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
        //   warpId: "attention_list1", //父布局的id (1.3.5版本支持传入dom元素)
        //   icon:
        //     "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1581999996960&di=f8203143f4c2c96ed36b88444a52f568&imgtype=0&src=http%3A%2F%2Fimg.58cdn.com.cn%2Fdist%2Fjxedt%2Fpc%2Fproducts%2Fjxregister%2Fimages%2Fno_data.png", //图标,默认null,支持网络图
        //   tip: "暂无相关数据aaa~", //提示
        // },
      },
      attention_list: [],
    };
  },
  components: {
    MescrollVue,
  },
  computed: {
    ...mapState({
      currentConversation: (state) => state.conversation.currentConversation,
    }),
  },
  created() {},
  mounted() {
    this.$bus.$on("getFollow", this.getFloow);
  },
  methods: {
    getFloow() {
      this.mescroll2.resetUpScroll();
    },
    mescrollInit2(mescroll) {
      this.mescroll2 = mescroll; // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
    },
    upCallback2(page, mescroll) {
      let param = {};
      param.page = page.num;
      param.title = this.search;

      this.$api.getim.attention_list(param).then((res) => {
        if (res.data.code == 200) {
          let arr = res.data.result.data;
          // 如果是第一页需手动置空列表
          if (page.num === 1) this.attention_list = [];
          // 下拉刷新
          // 把请求到的数据添加到列表
          this.attention_list = this.attention_list.concat(arr);
          // 数据渲染成功后,隐藏下拉刷新的状态
          this.$nextTick(() => {
            mescroll.endSuccess(arr.length);
          });
        } else {
          mescroll.endErr();
        }
      });
      // }
    },
    select(im, item) {
      this.$store.dispatch("checkoutConversation", "C2C" + im);
      //   console.log("kkkk", item, this.currentConversation);
      // this.$emit("selectUserId", item.im);
      this.$store.commit("setHeaderShow", true);
    },
  },
  beforeRouteEnter(to, from, next) {
    // 如果没有配置回到顶部按钮或isBounce,则beforeRouteEnter不用写
    next((vm) => {
      // 找到当前mescroll的ref,调用子组件mescroll-vue的beforeRouteEnter方法
      // 进入路由时,滚动到原来的列表位置,恢复回到顶部按钮和isBounce的配置
      vm.$refs.mescroll2 && vm.$refs.mescroll2.beforeRouteEnter(); // 进入路由时,滚动到原来的列表位置,恢复回到顶部按钮和isBounce的配置
    });
  },
  beforeRouteLeave(to, from, next) {
    // 如果没有配置回到顶部按钮或isBounce,则beforeRouteLeave不用写
    // 找到当前mescroll的ref,调用子组件mescroll-vue的beforeRouteLeave方法// 退出路由时,记录列表滚动的位置,隐藏回到顶部按钮和isBounce的配置
    this.$refs.mescroll2 && this.$refs.mescroll2.beforeRouteLeave(); // 退出路由时,记录列表滚动的位置,隐藏回到顶部按钮和isBounce的配置
    next();
  },
};
</script>
<style lang='less' scoped>
.current-conversation-item {
  background: #f2f5fa;
}
#attention_list {
  height: calc(100vh - 180px);
  background: #fff;
}
.liuyan {
  color: #9fa3b0;
  font-size: 14px;
  padding-right: 35px;
  text-align: left;
}
div.user_time {
  font-size: 13px;
  color: #9fa3bc;
  text-align: left;
}
.list:hover {
  background: #f2f5fa !important;
}
ul li {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 20px;
  background: #ffffff;
  position: relative;
  .is_online_true {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ad847;
    position: absolute;
    right: 15px;
    top: 50px;
  }
  .is_online_false {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ad847;
    position: absolute;
    right: 15px;
    top: 50px;
  }
  .acter_user {
    position: relative;
    width: 25%;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    > span {
      position: absolute;
      top: 0;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background: #fa6a43;
      right: 0px;
      color: #fff;
    }
  }
  .acter_text {
    width: 70%;
    margin-left: 15px;

    :first-child {
      display: flex;
      justify-content: space-between;
      flex-wrap: nowrap;
      align-items: flex-start;

      > div.user_im {
        text-align: left;
        font-size: 16px;
        color: #333;
        margin-bottom: 5px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
    }
  }
}
.im_avatar {
  // width: 40px !important;
  // height: 40px;
  width: 80%;
  border-radius: 50%;
  vertical-align: middle;
}

.noneData {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-top: 150px;
  > img {
    width: 100px;
    height: 100px;
  }
  span {
    margin-top: 20px;
    font-size: 14px;
    color: gray;
  }
}
</style>
